#include <vector>
#include <algorithm>

class Solution {
public:
    int findDuplicate(std::vector<int>& nums) {
        std::make_heap(nums.begin(), nums.end());
        std::sort_heap(nums.begin(), nums.end());
        int n = nums[0];
        for (int i = 1; i < nums.size(); i++){
            if (nums[i]==n) return n;
            n = nums[i];
        }
        return -1;
    }
};